let studentsPromise = [];

/** 学生编辑Promise */
export const getStudentsPromise = () => {
  let resolver;
  let rejecter;
  const nextPromise = new Promise((resolve, reject) => {
    resolver = resolve;
    rejecter = reject;
  });

  studentsPromise.push({ resolver, rejecter });

  return nextPromise;
};

/** 用户保存了一个地址 */
export const resolveStudents = (students) => {
  const allStudents = [...studentsPromise];
  studentsPromise = [];

  console.info('用户保存了一个子女', students);

  allStudents.forEach(({ resolver }) => resolver(students));
};

/** 取消编辑 */
export const rejectStudents = () => {
  const allStudents = [...studentsPromise];
  studentsPromise = [];

  allStudents.forEach(({ rejecter }) => rejecter(new Error('cancel')));
};
export const clearStudentsPromise = () => {
  studentsPromise = [];
}
